import * as echarts from 'echarts/core';
import { ECharts } from 'echarts';
// 系列类型的定义后缀都为 SeriesOption
import {
    BarChart,
    BarSeriesOption,
    LineChart,
    LineSeriesOption
} from 'echarts/charts';
// 组件类型的定义后缀都为 ComponentOption
import {
    TitleComponent,
    TitleComponentOption,
    TooltipComponent,
    TooltipComponentOption,
    GridComponent,
    GridComponentOption,
    DatasetComponent, // 数据集组件
    DatasetComponentOption, // 内置数据转换器组件 (filter, sort)
    TransformComponent
} from 'echarts/components';
import { LabelLayout, UniversalTransition } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';

// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型
type ECOption = echarts.ComposeOption<
    | BarSeriesOption
    | LineSeriesOption
    | TitleComponentOption
    | TooltipComponentOption
    | GridComponentOption
    | DatasetComponentOption
>;

// 未找到init的变量声明，自己定义了一下
interface ECInit extends ECharts {
    init: (e: HTMLElement) => {
        setOption: (e: ECOption) => void
    }
}

// 注册必须的组件
echarts.use([
    TitleComponent,
    TooltipComponent,
    GridComponent,
    DatasetComponent,
    TransformComponent,
    LabelLayout,
    UniversalTransition,
    CanvasRenderer,
    BarChart,
    LineChart
]);

export {
    echarts, ECInit, ECOption
}